﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Billing.WindowsBase;

namespace Billing.CashDesk
{
    public partial class MainForm : Billing.WindowsBase.FormBase
    {
        public MainForm()
        {
            InitializeComponent();
            this.Text = "გადახდების პროგრამა - " + CashDeskSettings.PaymentPointName;
            FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
            this.WindowState = FormWindowState.Maximized;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (Program.IsFirstLogin)
            {
                PassChangeForm frm = new PassChangeForm(true);
                MessageBox.Show("პაროლი არ შეიძლება იყოს ცარიელი მნიშვნელობა, აუცილებელია პაროლის შეცვლა", "შეტყობინება");
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    Application.Exit();
                }
            }
            ultraStatusBar1.Panels["StatusText"].Text = CashDeskSettings.PaymentPointName + " - " + Profile.UserFullName;
        }

        void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!FormManager.AllowQuit)
            {
                FormManager.AllowQuit = true;
                e.Cancel = true;
                return;
            }

            if (MessageBox.Show("დავასრულო პროგრამაში მუშაობა?", "გამოსვლა", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.No)
            {
                FormManager.AllowQuit = true;
                e.Cancel = true;
                return;
            }

            Program.IsAuthorized = false;
        }

        private void btCashDeskPaymentOrders_Click(object sender, EventArgs e)
        {
            PrintDoc doc = new PrintDoc();
            doc.Path = "/BillingReports/CashDeskPaymentOrders";
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("peymentOrderTypeID", (string)null));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("paymentPointID", CashDeskSettings.PaymentPointID.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("userID", Profile.UserID.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("startDate", DateTime.Today.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("endDate", DateTime.Today.AddDays(1).AddMilliseconds(-1).ToString()));
            ucPrintControl1.PrintDoc = doc;
            ucPrintControl1.ReportRefresh();
        }

        private void btCashDeskCashierReport_Click(object sender, EventArgs e)
        {
            PrintDoc doc = new PrintDoc();
            doc.Path = "/BillingReports/CashDeskCashierReport";
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("peymentOrderTypeID", (string)null));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("paymentPointID", CashDeskSettings.PaymentPointID.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("userID", Profile.UserID.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("startDate", DateTime.Today.ToString()));
            doc.ReporParameteres.Add(new Microsoft.Reporting.WinForms.ReportParameter("endDate", DateTime.Today.AddDays(1).AddMilliseconds(-1).ToString()));
            ucPrintControl1.PrintDoc = doc;
            ucPrintControl1.ReportRefresh();
        }

        private void btSearchInvoice_Click(object sender, EventArgs e)
        {
            PrintDoc doc = new PrintDoc();
            doc.Path = "/BillingReports/CashDeskInvoicesSearch";
            ucPrintControl1.PrintDoc = doc;
            ucPrintControl1.ReportRefresh();
        }

        private void ultraStatusBar1_ButtonClick(object sender, Infragistics.Win.UltraWinStatusBar.PanelEventArgs e)
        {
            switch (e.Panel.Key)
            {
                case "PasswordChange":
                    using (PassChangeForm frm = new PassChangeForm())
                    {
                        frm.ShowDialog();
                    }
                    break;
                case "about":
                    using (AboutForm frm = new AboutForm())
                    {
                        frm.ShowDialog(this);
                    }
                    break;
                default:
                    break;
            }
        }

    }
}
